<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>

    class Father {
        constructor(x, y) {
            this.x = x;
            this.y = y;
        }

        money() {
            console.log(100)
        }

        sum() {
            console.log(this.x + this.y)
        }

        say() {
            console.log('我是爸爸')
        }
    }

    class Son extends Father {

        /**
         * 子类的构造器显示声明了, 那么构造器第一行必须要调用父类的构造器
         * 没有声明子类构造器, 默认就调用了
         */
        constructor(x, y) {
            super(x, y);
            this.x = x;
            this.y = y;
        }

        /**
         * JS是存在类似(实现方式不一样) -> Java中的重写 @Override, 但不存在方法重载
         */
        say() {
            super.say();
            console.log('我是儿子');
        }

        subtract() {
            console.log(this.x - this.y)  // NaN
        }

    }

    let son = new Son(2, 5);
    son.money();
    son.sum();
    son.say();
    son.subtract();
</script>
</body>
</html>
